// pages/partnercenter/commissiondetail/commissiondetail.js
var shihan = require('../../../common/fetch')
var config = require('../../../common/config')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    page_size: 20,
    currentTab: 0,
    all_order_list: [],
    orderlistflag: true,
    showLoading: true,
    res_navbar: ['全部', '未到账', '累计到账', '售后'],
    reminder: [{
      'tit': '您还没有佣金',
      'word': '点滴积累，终成飞跃~'
    }, {
      'tit': '您还没有未到账佣金',
      'word': '所谓真正的财富，也就是超出必须的盈余~'
    }, {
      'tit': '您还没有已到账佣金',
      'word': '人生获取财富的能力，不在能知，乃在能行~'
    }, {
      'tit': '您还没有相关售后',
      'word': '每天告诉自己一次，我真的很不错~'
    }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      currentTab: Number(options.index)
    })
    this.changeorderlist(this.data.currentTab)
  },
  onResNavbarTap: function(e) {
    this.setData({
      page: 1,
      page_size: 20,
      all_order_list: [],
      showLoading: true,
      currentTab: e.currentTarget.dataset.index
    })
    this.changeorderlist(e.currentTarget.dataset.index)
  },
  refreshorderlist: function(a) {
    var that = this
    // that.getauthorize()
    shihan.sendRequest(a, 'POST', {
        page: that.data.page,
        page_size: that.data.page_size
      }, {})
      .then(function(response) {
        if (response.data.code == 0 && response.data.data.sh_order.length > 0) {
          that.setData({
            page: that.data.page + 1,
            all_order_list: that.data.all_order_list.concat(response.data.data.sh_order),
            orderlistflag: true,
            showLoading: false
          })
        } else {
          that.setData({
            orderlistflag: false,
            showLoading: false
          })
        }
      }, function(error) {
        console.log(error);
      });
  },
  changeorderlist: function(tabindex) {
    // console.log(this.data.all_order_list)
    switch (Number(tabindex)) {
      case 0:
        this.refreshorderlist(config.partner_order_list) //全部
        break;
      case 1:
        this.refreshorderlist(config.partner_pay_order_list) //未到账
        break;
      case 2:
        this.refreshorderlist(config.partner_complete_order_list) //已到账
        break;
      case 3:
        this.refreshorderlist(config.partner_refund_order_list) //售后
        break;
    }
  },
  myorderdetail: function(e) { //redirectTo
    wx.navigateTo({
      url: '/pages/other/myorderdetail/myorderdetail?orderid=' + e.currentTarget.dataset.orderid,
    })
  },
  tradelook: function(e) {
    wx.navigateTo({
      url: '/pages/other/viewlogistics/viewlogistics?index=1&id=' + e.currentTarget.dataset.courierid,
    })
  },
  loadMoreData: function() {
    var that = this
    if (that.data.orderlistflag) {
      that.setData({
        orderlistflag: false
      })
      this.changeorderlist(this.data.currentTab)
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  }
})